
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    {$LOAD_STYLE.top|raw}
</head>
<style>
	.copyurl{
		cursor: pointer;
	}
</style>
<script src="__JS__/clipboard.min.js"></script>
<body class="pear-container">
<div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
        <div class="layui-card">
            <form class="layui-form edit-form" method="post" action="">
            <div class="layui-tab layui-tab-brief" lay-filter="TabBrief">
                <ul class="layui-tab-title">
					<li class="layui-this">打印配置</li>
					<li>其他配置</li>
					<li >网站设置</li>
					<li>邮箱设置</li>
                </ul>
                <div class="layui-tab-content">					
					<div class="layui-tab-item layui-show">
						<fieldset class="layui-elem-field layui-field-title">
							<legend class="layui-font-16">打印机配置</legend>
							<div class="layui-field-box">
								
								<div class="layui-form-item">
									<label class="layui-form-label">
										打印端IP
									</label>
									<div class="layui-input-block">
										<input id="print_ip" autocomplete="off" class="layui-input" name="print[ip]" value="{$data['print']['ip']??'127.0.0.1'}" placeholder="" type="text"/>
										<div class="layui-form-mid layui-word-aux">一般默认 127.0.0.1</div>
									</div>
								</div>
								
								<div class="layui-form-item">
									<label class="layui-form-label">
										打印端口
									</label>
									<div class="layui-input-block">
										<input id="print_port" autocomplete="off" class="layui-input" name="print[port]" value="{$data['print']['port']??'12345'}" placeholder="" type="text"/>
										<div class="layui-form-mid layui-word-aux">一般默认12345，请核对您本机打印控件端口</div>
									</div>
								</div>
								
								<div class="layui-form-item">
									<label class="layui-form-label">
										打印预览
									</label>
									<div class="layui-input-block">
										{:lay_switch('print[preview]',$data['print']['preview']??1,'开启|关闭')}
									</div>
									<div class="layui-form-mid layui-word-aux">关闭预览，打印时将会直接打印</div>
								</div>
								
								<div class="layui-form-item">
                                    <div class="layui-form-item">
                                    	<label class="layui-form-label">
                                    		A4打印机
                                    	</label>
                                    	<div class="layui-input-block">
                                    		<select id="Printer1" name="print[printer_name]" lay-verify="required" verify="must"'>
                                    			<option value=""></option>
                                    		</select>
                                    		<div class="layui-form-mid layui-word-aux">喷墨式A4默认打印机</div>
                                    	</div>
                                    </div>
                                    
									<label class="layui-form-label">
										标签打印机
									</label>
									<div class="layui-input-block">
										<select id="Printer2" name="print[printer_name2]" lay-verify="required" verify="must"'>
											<option value=""></option>
										</select>
										<div class="layui-form-mid layui-word-aux">热敏标签默认打印机名</div>
									</div>
								</div>

								<div class="layui-form-item">
									<label class="layui-form-label">
										针式打印机
									</label>
									<div class="layui-input-block">
										<select id="Printer3" name="print[printer_name3]" lay-verify="required" verify="must"'>
											<option value=""></option>
										</select>
										<div class="layui-form-mid layui-word-aux">码单针式默认打印机</div>
									</div>
								</div>
							</div>
						</fieldset>
					</div>
					
					<div class="layui-tab-item">
						<div class="layui-form-item">
							<label class="layui-form-label">
								历年销售数据：
							</label>
							<div class="layui-input-block">
								{:lay_switch('other[history_sale]',$data['other']['history_sale']??'','显示|隐藏')}
							</div>
							<div class="layui-form-mid layui-word-aux">隐藏后，历年统计的销售报表将不显示</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">
								统计敏感数据：
							</label>
							<div class="layui-input-block">
								{:lay_switch('other[sensitive_data]',$data['other']['sensitive_data']??'','显示|隐藏')}
							</div>
							<div class="layui-form-mid layui-word-aux">隐藏后，报表敏感数据将会隐藏不显示</div>
						</div>
					</div>
					
					<div class="layui-tab-item">
					        <div class="layui-form-item">
					            <label class="layui-form-label">
					                网站标题
					            </label>
					            <div class="layui-input-block">
					                <input autocomplete="off" class="layui-input" name="web[title]" value="{$data['web']['title']??''}" type="text"/>
					            </div>
					        </div>
					        <div class="layui-form-item">
					            <label class="layui-form-label">
					                网站关键词
					            </label>
					            <div class="layui-input-block">
					                <input autocomplete="off" class="layui-input"  name="web[key]" value="{$data['web']['key']??''}" type="text"/>
					            </div>
					        </div>
					        <div class="layui-form-item">
					            <label class="layui-form-label">
					                网站描述
					            </label>
					            <div class="layui-input-block">
					                <textarea name="web[desc]" class="layui-textarea">{$data['web']['desc']??''}</textarea>
					            </div>
					        </div>
					        <div class="layui-form-item">
					            <label class="layui-form-label">
					                电话
					            </label>
					            <div class="layui-input-block">
					                <input autocomplete="off" class="layui-input"  name="web[tel]" value="{$data['web']['tel']??''}" type="text"/>
					            </div>
					        </div>
					        <div class="layui-form-item">
					            <label class="layui-form-label">
					                QQ
					            </label>
					            <div class="layui-input-block">
					                <input autocomplete="off" class="layui-input"  name="web[qq]" value="{$data['web']['qq']??''}" type="text"/>
					            </div>
					        </div>
					        <div class="layui-form-item">
					            <label class="layui-form-label">
					                邮箱
					            </label>
					            <div class="layui-input-block">
					                <input autocomplete="off" class="layui-input"  name="web[mail]" value="{$data['web']['mail']??''}" type="text"/>
					            </div>
					        </div>
					        <div class="layui-form-item">
					            <label class="layui-form-label">
					                地址
					            </label>
					            <div class="layui-input-block">
					                <input autocomplete="off" class="layui-input"  name="web[addr]" value="{$data['web']['addr']??''}" type="text"/>
					            </div>
					        </div>
					        <div class="layui-form-item layui-img-upload">
					            <label class="layui-form-label">
					                网站LOGO
					            </label>
					            <div class="layui-input-block">
					                {:opt_photo('logo')}
					            <button class="pear-btn pear-btn-primary pear-btn-sm  upload-image" type="button">
					                    <i class="fa fa-image">
					                    </i>
					                    上传图片
					                </button>
					                <input lay-verify="uploadlogo" name="web[logo]" type="hidden" value="{$data['web']['logo']??''}"/>
					                <div class="upload-image">
					                    <span>
					                    </span>
					                    <img class="upload-image" src="{$data['web']['logo']??''}"/>
					                </div>
					            </div>
					        </div>
					        <div class="layui-form-item layui-img-upload">
					            <label class="layui-form-label">
					                网站海报
					            </label>
					            <div class="layui-input-block">
					                {:opt_photo('bg')}
					            <button class="pear-btn pear-btn-primary pear-btn-sm upload-image" type="button">
					                    <i class="fa fa-image">
					                    </i>
					                    上传图片
					                </button>
					                <input lay-verify="uploadbg" name="web[bg]" type="hidden" value="{$data['web']['bg']??''}"/>
					                <div class="upload-image">
					                    <span>
					                    </span>
					                    <img class="upload-image" src="{$data['web']['bg']??''}"/>
					                </div>
					            </div>
					        </div>
					</div>
					<div class="layui-tab-item">
					        <div class="layui-form-item">
					        <label class="layui-form-label">
					            邮箱账号
					        </label>
					        <div class="layui-input-block">
					            <input autocomplete="off" class="layui-input" name="web[smtp-user]" value="{$data['web']['smtp-user']??''}" type="text"/>
					        </div>
					    </div>
					    <div class="layui-form-item">
					        <label class="layui-form-label">
					            邮箱密匙
					        </label>
					        <div class="layui-input-block">
					            <input autocomplete="off" class="layui-input"  name="web[smtp-pass]" value="{$data['web']['smtp-pass']??''}" type="text"/>
					        </div>
					    </div>
					    <div class="layui-form-item">
					        <label class="layui-form-label">
					            邮箱端口
					        </label>
					        <div class="layui-input-block">
					            <input autocomplete="off" class="layui-input"  name="web[smtp-port]" value="{$data['web']['smtp-port']??''}" type="text"/>
					        </div>
					    </div>
					    <div class="layui-form-item">
					        <label class="layui-form-label">
					            邮箱服务器
					        </label>
					        <div class="layui-input-block">
					            <input autocomplete="off" class="layui-input"  name="web[smtp-host]" value="{$data['web']['smtp-host']??''}" type="text"/>
					        </div>
					    </div>
					</div>
				</div>  
                <div class="layui-input-block" style="min-height: 80px;">
                    <button type="submit" class="pear-btn pear-btn-primary">保存</button>
                    <button type="reset" class="pear-btn">重置</button>
                </div>
        </form>    
        </div>
    </div>
</div>
<script src="__JS__/jquery.1.8.3.js"></script>
<script>
    layui.use(['form', 'jquery', 'uploads','mycomm'], function() {
        let form = layui.form;
        let $ = layui.jquery;
		let mycomm = layui.mycomm;
		
		var ip = $("#print_ip").val();
		var port = $("#print_port").val();
		
		if(ip==""||port==""){
			alert("ip,port不能为空");
			return false;
		}
		
		$("#PrinterS").empty();
		
		var msg = '{"method":"getprinterlist","token":"aa","taskid":"1234567"}';
		
		$(document).ready(function(){
			jQuery.support.cors = true;
			$.get(
			"http://"+ip+":"+port+'/?time='+new Date().getTime(),
			function (data, status, jqxhr) {				
				jQuery.support.cors = true;		
				$.ajax({
					async : false,
					url : "http://"+ip+":"+port+"/",
					type : "POST",
					contentType: "application/x-www-form-urlencoded",
					dataType : "json",
					xhrFields: {withCredentials: false},
					crossDomain: true, 
					data : msg,
					beforeSend: function (XMLHttpRequest) {
						 // beforeSend 函数里 不允许添加任何 东西	
			             //XMLHttpRequest.setRequestHeader("token", 'abcd1234'); //不允许 使用jQuery发送AJAX请求时在header中添加Token
			        },
					success: function(data){
						console.log(JSON.stringify(data));			
						if(data.status=="ok"){
							layui.use(['layer', 'form'], function () {
								var form = layui.form;
								var length = data.length;
								var html1 = '';
								var html2 = '';
								for(var o in data.data){
									var printname = data.data[o].name;
									html1 += '<dd lay-value="' + printname + '">' + printname + '</dd>';
									html2 += '<option value="' + printname + '">' + printname + '</option>';
								}
								var select ={
									1:'dd[lay-value="{$data['print']['printer_name']??''}"]',
									2:'dd[lay-value="{$data['print']['printer_name2']??''}"]',
									3:'dd[lay-value="{$data['print']['printer_name3']??''}"]',
								};
								
								for(var i=1;i<4;i++){
									$("#Printer"+i).next().children().eq(1).append(html1);
									$("#Printer"+i).append(html2);
									form.render();//没有写这个，操作后没有效果
									// 查找点击
									$('#Printer'+i).siblings("div.layui-form-select").find('dl').find(select[i]).click();
									// 再次渲染select
									form.render('select');
								}
							});								 
						}else{
							alert("打印失败:"+data.data);
						}
					},
					error: function(data){
						console.log(JSON.stringify(data));
						alert("连接HttpPrinter失败:"+JSON.stringify(data));
					}
				});
			}).fail(function () {
				alert('链接失败');
			});
		});
    });
</script>
{$LOAD_STYLE.bottom|raw}
</body>
</html>
